app.controller("userController",function($scope, $controller, $location, userService){
    $controller('baseController',{$scope:$scope, baseService:userService});

    $scope.find = function () {
        userService.find().success(function (res) {
            if(res.success){
                $scope.user = res.data;
            }else {
                alert("当前未登录状态");
                location.href = "login.html";
            }
        });
    };

    $scope.updPassword = function(){
        var others = $scope.others;
        if(!others.oldPassword){
            alert("旧密码不能为空");
            return;
        }
        if(!others.newPassword1){
            alert("新密码不能为空");
            return;
        }
        if(!others.newPassword2){
            alert("新密码不能为空");
            return;
        }
        if(others.newPassword1 !== others.newPassword2){
            alert('密码不一致');
            return;
        }
        if(others.newPassword1.length < 6){
            alert("密码长度必须大于6位");
            return;
        }
        if(others.newPassword1.length > 16){
            alert("密码长度必须小于16位");
            return;
        }
        userService.updPassword({others:others}).success(function (res) {
            $scope.resHandler(res, function (res) {
               alert("修改成功");
            });
            $scope.others = {};
        });

    }

    $scope.init = function () {
        $scope.others = {};
        $scope.find();
    }


});
